package spec.ecore;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EClassImpl;
import org.eclipse.emf.ecore.impl.EOperationImpl;

public class EcoreClass {

	private String name;
	private ArrayList<String[]> attrvar_list;
	private HashMap<String, EcoreMethod> method_list;

	public EcoreClass(EClassImpl eClass) {
		name = eClass.getName();
		attrvar_list = new ArrayList<String[]>();
		method_list = new HashMap<String, EcoreMethod>();

		for (EStructuralFeature next : eClass.getEAllStructuralFeatures()) {
			String type = "";
			String name = next.getName();
			if (next.getEType() != null) {
				type = next.getEType().getName();
			}

			attrvar_list.add(new String[] { name, type });

		}

		for (EOperation next : eClass.getEAllOperations()) {
			if (next instanceof EOperationImpl) {
				EcoreMethod eMothod = new EcoreMethod((EOperationImpl) next);
				method_list.put(eMothod.getName(), eMothod);
			}
		}
	}

	public String getName() {
		return name;
	}

	public Collection<EcoreMethod> getAllMethod() {
		return method_list.values();
	}

	public ArrayList<String[]> getAttrVar() {
		ArrayList<String[]> list = new ArrayList<String[]>();

		for (String[] next : attrvar_list) {
			list.add(next);
		}

		return list;
	}

	public List<String[]> getAttrvarList(){

		return attrvar_list;
	}
	
	public List<String[]> getParamVariable(String methodName) {
		List<String[]> list = new ArrayList<String[]>();

		if (method_list.size() > 0) {

			List<String[]> param_list = method_list.get(methodName).getParam_list();
			for (String[] next : param_list) {
				list.add(next);
			}

		}

		return list;
	}
}
